package edu.scau.misp.backend_module.controller;


import edu.scau.misp.backend_module.core.domain.AjaxResult;
import edu.scau.misp.backend_module.domain.Dish;
import edu.scau.misp.backend_module.domain.Table;
import edu.scau.misp.backend_module.service.ITableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("table")
public class TableController {

    @Autowired
    ITableService tableService;
    @GetMapping("/id/{tableId}")
    public AjaxResult getTableById(@PathVariable("tableId")Long tableId) {
        return AjaxResult.success(tableService.getTableById(tableId));
    }

    @GetMapping("/listAll")
    public AjaxResult listAllTable(){
        return AjaxResult.success(tableService.listAllTable());
    }


    @GetMapping("/list")
    public AjaxResult list(Table table) {
        List<Table> list = tableService.selectTableList(table);
        return AjaxResult.success(list);
    }
    @PostMapping
    public AjaxResult add(@RequestBody Table table) {
        int rows = tableService.insertTable(table);
        return rows > 0 ? AjaxResult.success("添加餐桌成功") : AjaxResult.error("添加餐桌失败");
    }

    @PutMapping
    public AjaxResult edit(@RequestBody Table table) {
        int rows = tableService.updateTable(table);
        return rows > 0 ? AjaxResult.success("修改餐桌成功") : AjaxResult.error("修改餐桌失败");
    }
    @DeleteMapping("/{tableId}")
    public AjaxResult remove(@PathVariable("tableId") Long tableId) {
        int rows = tableService.deleteTableById(tableId);
        return rows > 0 ? AjaxResult.success("删除餐桌成功") : AjaxResult.error("删除餐桌失败");
    }






}
